import { ajax } from "./util.js"

let title = document.querySelector("#title")
let content = document.querySelector("#content")

let btn = document.querySelector("button")

function getQueryString(name) {
    const url_string = window.location.href
    const url = new URL(url_string);
    return url.searchParams.get(name);
}

let id = getQueryString("id")

ajax.post("/editData", { id }, function (data) {
    title.value = data.title
    content.value = data.content
    console.log(data)
})

btn.onclick = function () {
    let titleV = title.value
    let contentV = content.value
    ajax.post("http://localhost/edit", { id, titleV, contentV })
    window.location.href = "/list"
}